home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / other / jikes / src / control.cpp < prev    next >
C/C++ Source or Header  |  1999-05-14  |  46KB  |  1,197 lines

  1. // $Id: control.cpp,v 1.4 1999/03/10 19:59:21 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #include "config.h"
  11. #include <sys/stat.h>
  12. #include "control.h"
  13. #include "scanner.h"
  14. #include "parser.h"
  15. #include "semantic.h"
  16. #include "unicode.h"
  17. #include "error.h"
  18. #include "bytecode.h"
  19.  
  20. Control::Control(ArgumentExpander &arguments, Option &option_) : return_code(0),
  21.                                                                  option(option_),
  22.                                                                  dot_classpath_index(0),
  23.                                                                  system_semantic(NULL),
  24.                                                                  semantic(1024),
  25.                                                                  needs_body_work(1024),
  26.                                                                  type_trash_bin(1024),
  27.                                                                  input_java_file_set(1021),
  28.                                                                  input_class_file_set(1021),
  29.                                                                  expired_file_set(),
  30.                                                                  recompilation_file_set(1021),
  31.                                                                  Object_type(NULL),
  32.                                                                  Cloneable_type(NULL),
  33.                                                                  Serializable_type(NULL),
  34.                                                                  String_type(NULL),
  35.                                                                  Void_type(NULL),
  36.                                                                  Boolean_type(NULL),
  37.                                                                  Byte_type(NULL),
  38.                                                                  Short_type(NULL),
  39.                                                                  Character_type(NULL),
  40.                                                                  Integer_type(NULL),
  41.                                                                  Long_type(NULL),
  42.                                                                  Float_type(NULL),
  43.                                                                  Double_type(NULL),
  44.                                                                  Class_type(NULL),
  45.                                                                  StringBuffer_type(NULL),
  46.                                                                  Throwable_type(NULL),
  47.                                                                  RuntimeException_type(NULL),
  48.                                                                  Error_type(NULL),
  49.                                                                  int_pool(&bad_value),
  50.                                                                  long_pool(&bad_value),
  51.                                                                  float_pool(&bad_value),
  52.                                                                  double_pool(&bad_value),
  53.                                                                  Utf8_pool(&bad_value)
  54.  
  55. #ifdef TEST
  56.                                                                , line_count(0), 
  57.                                                                  class_files_read(0),
  58.                                                                  class_files_written(0),
  59.                                                                  class_file_id(0),
  60.                                                                  input_files_processed(0)
  61. #endif
  62. {
  63.     ProcessGlobalNameSymbols();
  64.  
  65.     ProcessUnnamedPackage();
  66.  
  67.     ProcessPath();
  68.  
  69.     ProcessSystemInformation();
  70.  
  71.     //
  72.     // Instantiate a scanner and a parser and initialize the static members for the semantic processors.
  73.     //
  74.     scanner = new Scanner(*this);
  75.     parser = new Parser();
  76.     SemanticError::StaticInitializer();
  77.  
  78.     //
  79.     // Process all file names specified in command line
  80.     //
  81.     ProcessNewInputFiles(input_java_file_set, arguments, option.first_file_index);
  82.  
  83.     //
  84.     // For each input file, copy it into the input_files array and process its package declaration.
  85.     //
  86.     StoragePool *ast_pool = new StoragePool(64); // how much space do we need? estimate 64 tokens.
  87.     FileSymbol **input_files = new FileSymbol*[input_java_file_set.Size() + 1];
  88.     int num_files = 0;
  89.     for (FileSymbol *file_symbol = (FileSymbol *) input_java_file_set.FirstElement();
  90.                      file_symbol;
  91.                      file_symbol = (FileSymbol *) input_java_file_set.NextElement())
  92.     {
  93.         input_files[num_files++] = file_symbol;
  94.         scanner -> Scan(file_symbol);
  95.         if (file_symbol -> lex_stream) // did we have a successful scan!
  96.         {
  97.             AstPackageDeclaration *package_declaration = parser -> PackageHeaderParse(file_symbol -> lex_stream, ast_pool);
  98.             ProcessPackageDeclaration(file_symbol, package_declaration);
  99.             ast_pool -> Reset();
  100.         }
  101.     }
  102.  
  103.     //
  104.     // 
  105.     //
  106.     FileSymbol *main_file_clone;
  107.     if (num_files > 0)
  108.         main_file_clone = input_files[0] -> Clone();
  109.     else
  110.     {
  111.         //
  112.         // Some name, any name !!! We use dot_name_symbol as a bad file name because
  113.         // no file can be named ".".
  114.         //
  115.         FileSymbol *file_symbol = classpath[dot_classpath_index] -> RootDirectory() -> InsertFileSymbol(dot_name_symbol);
  116.         file_symbol -> directory_symbol = classpath[dot_classpath_index] -> RootDirectory();
  117.         file_symbol -> SetJava();
  118.  
  119.         main_file_clone = file_symbol -> Clone();
  120.     }
  121.  
  122.     main_file_clone -> semantic = new Semantic(*this, main_file_clone);
  123.     system_semantic = main_file_clone -> semantic;
  124.     scanner -> SetUp(main_file_clone);
  125.  
  126. #ifdef WIN32_FILE_SYSTEM
  127.     //
  128.     //
  129.     //
  130.     if (option.BadMainDisk())
  131.     {
  132.         system_semantic -> ReportSemError(SemanticError::NO_CURRENT_DIRECTORY,
  133.                                           0,
  134.                                           0);
  135.     }
  136. #endif
  137.  
  138.     //
  139.     //
  140.     //
  141.     for (int o = 0; o < option.bad_options.Length(); o++)
  142.     {
  143.         system_semantic -> ReportSemError((SemanticError::SemanticErrorKind) option.bad_options[o] -> kind,
  144.                                           0,
  145.                                           0,
  146.                                           option.bad_options[o] -> name);
  147.     }
  148.  
  149.     //
  150.     //
  151.     //
  152.     for (int l = 0; l < bad_zip_filenames.Length(); l++)
  153.     {
  154.         system_semantic -> ReportSemError(SemanticError::CANNOT_OPEN_ZIP_FILE,
  155.                                           0,
  156.                                           0,
  157.                                           bad_zip_filenames[l]);
  158.     }
  159.  
  160.     //
  161.     //
  162.     //
  163.     if (system_package -> directory.Length() == 0)
  164.     {
  165.         system_semantic -> ReportSemError(SemanticError::PACKAGE_NOT_FOUND,
  166.                                           0,
  167.                                           0,
  168.                                           StringConstant::US_java_SL_lang);
  169.     }
  170.  
  171.     //
  172.     // When the -d option is specified, create the relevant
  173.     // directories if they don't already exist.
  174.     //
  175.     if (option.directory)
  176.     {
  177.         if (! ::SystemIsDirectory(option.directory))
  178.         {
  179.             for (char *ptr = option.directory; *ptr; ptr++)
  180.             {
  181.                 char delimiter = *ptr;
  182.                 if (delimiter == U_SLASH)
  183.                 {
  184.                     *ptr = U_NULL;
  185.  
  186.                     if (! ::SystemIsDirectory(option.directory))
  187.                         ::SystemMkdir(option.directory);
  188.  
  189.                     *ptr = delimiter;
  190.                 }
  191.             }
  192.  
  193.             ::SystemMkdir(option.directory);
  194.  
  195.             if (! ::SystemIsDirectory(option.directory))
  196.             {